package com.jessechanrui.template.common.template.auth.infrastructure.feign;

import com.jessechanrui.template.common.template.auth.application.dto.req.UpdateUserPasswordRequest;
import com.jessechanrui.template.common.template.auth.infrastructure.feign.authcenter.*;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.Valid;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * 任务管理平台认证中心
 */
@FeignClient(name = "auth-center-service", url = "${auth.center.url}")
public interface AuthCenterFegin {

    /**
     * 用户登录获取访问令牌
     *
     * @param username 用户名
     * @param password 密码
     * @param decode   密码是否加密
     * @return
     */
    @PostMapping(value = "/login", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    LoginResponse login(@RequestParam String username, @RequestParam String password,
                        @RequestParam(value = "decode", defaultValue = "false") boolean decode);

    /**
     * 退出登录
     * @return
     */
    @PostMapping(value = "/logout")
    AuthCenterBaseResponse<Object> logout(@RequestHeader("Authorization") String authorization);

    /**
     * 查询全量用户
     *
     * @return
     */
    @GetMapping(value = "/users")
    UsersResponse users(@RequestHeader("Authorization") String authorization);

    /**
     * 当前登录用户
     *
     * @param authorization
     * @return
     */
    @GetMapping(value = "/current/user")
    UserDetailResponse currentUser(@RequestHeader("Authorization") String authorization);

    /**
     * 当前登录用户的租户
     *
     * @param authorization
     * @return
     */
    @GetMapping(value = "/current/tenant")
    CurrentTenantResponse currentTenant(@RequestHeader("Authorization") String authorization);

    /**
     * 修改密码
     *
     * @param authorization
     * @param request
     * @return
     */
    @PutMapping(value = "/current/password")
    UserDetailResponse modifyPassword(@RequestHeader("Authorization") String authorization, @Valid @RequestBody UpdateUserPasswordRequest request);


    /**
     * 切换当前用户选中的租户
     *
     * @param tenantId
     * @return
     */
    @PutMapping(value = "/current/tenant", produces = MediaType.APPLICATION_JSON_VALUE)
    AuthCenterBaseResponse<Object> switchTenant(@RequestHeader("Authorization") String authorization, @Schema(description = "租户ID") @RequestParam String tenantId);


    /**
     * 获取当前登录用户关联的租户列表

     * @param authorization
     * @return
     */
    @GetMapping(value = "/current/tenants")
    TenantListResponse getCurrentTenants(@RequestHeader("Authorization") String authorization);

}
